package com.weimei.conversionTreasure.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.google.android.material.tabs.TabLayout;
import com.lxj.xpopup.XPopup;
import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.app.AppViewModelFactory;
import com.weimei.conversionTreasure.databinding.ActivityKhRecordBinding;
import com.weimei.conversionTreasure.viewModel.AddRecordVM;
import com.weimei.conversionTreasure.viewModel.KhRecordVM;
import com.weimei.conversionTreasure.weight.BottomDelPop;
import com.weimei.conversionTreasure.weight.BottomKhAddPop;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.tatarka.bindingcollectionadapter2.BR;

public class KhRecordActivity extends BaseActivity<ActivityKhRecordBinding, KhRecordVM> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_kh_record;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);

        binding.back.setOnClickListener(view -> finish());
        binding.add.setOnClickListener(view -> {
            new XPopup.Builder(this)
                    .moveUpToKeyboard(false)//如果不加这个，评论弹窗会移动到软键盘上面
                    .enableDrag(true)
                    .asCustom(new BottomKhAddPop(KhRecordActivity.this))
                    .show();
        });

        binding.khTab.addTab(binding.khTab.newTab().setText("经销商"));
        binding.khTab.addTab(binding.khTab.newTab().setText("客户"));
        binding.khTab.getTabAt(1).select();

        binding.khTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.type.set(""+tab.getPosition());
                viewModel.onResume();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    @Override
    public KhRecordVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, (ViewModelProvider.Factory) factory).get(KhRecordVM.class);
    }


}


